﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace mds.Queue.MSMQServer
{
     [DataContract]
   internal class MSMQServerConfig:IConfigurationSectionHandler
    {
         public List<ServiceConfig> ServiceList { set; get; }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            MSMQServerConfig configs = new MSMQServerConfig();
            configs.ServiceList = new List<ServiceConfig>();
            var nodes = section.SelectNodes("ServiceConfig");
            if (nodes != null)
            {
                for (var i = 0; i < nodes.Count; i++)
                {
                    var node = nodes[i];
                    var temp = new ServiceConfig() {
                        ServiceName = node.Attributes["ServerName"].Value,
                        Type = node.Attributes["Type"].Value
                    };
                    if (!string.IsNullOrEmpty(node.Attributes["IsDefault"].Value))
                    {
                        temp.IsDefault = Convert.ToBoolean(node.Attributes["IsDefault"].Value);
                    }
                    configs.ServiceList.Add(temp);
                }
            }
            return configs;
        }
    }
}
